
bool hasCycle(ListNode* head)
{
    unordered_set<ListNode*> s;
    while (head)
    {
        if (s.count(head) != 0)
        {
            return true;
        }
        s.insert(head);
        head = head->next;
    }
    return false;
}